<template>
  <view class="container">
    <!-- <uni-fab @fabClick="showDrawer()"></uni-fab>
	
	<uni-fab ref="fab" 
  :pattern="pattern"
  @trigger="trigger" 
  @fabClick="showDrawer" />


  <uni-drawer ref="showRight" mode="left">
      <scroll-view style="height: 100%" scroll-y="true">
        <user></user>
      </scroll-view>
    </uni-drawer>
 -->

  <department></department>
  <van-tabbar 
  :active=tabActive 
  activeColor="#ff6781"
  >
  <van-tabbar-item   icon="home-o">门诊</van-tabbar-item>
  <van-tabbar-item  icon="friends-o" data-info="person" @click="tabClickHandler($event)">个人</van-tabbar-item>
  <van-tabbar-item   icon="setting-o" data-info="feedback" @click="tabClickHandler($event)">反馈</van-tabbar-item>
  </van-tabbar>
    

</view>
  
</template>

<script>
import security from "../../api/security";
export default {
  onLoad(){
    (async () => {
      try {
        try {
          const userCode = await uni.getStorage({
            key: "userCode",
          });
          if (!userCode[0].data) {
            throw `读取失败`;
          }
        } catch (e) {
          try {
            const code = await uni.login();
            await uni.setStorage({
              key: "userCode",
              data: code.code,
            });
          } catch (e) {
            console.error("index", e);
            uni.showToast({
              title: `错误： ${e}`,
              icon: "error",
            });
          }
        }

        const userCode = (
          await uni.getStorage({
            key: "userCode",
          })
        ).data;
        const result = await security.login(userCode);
        if (result.statusCode !== 200) {
          throw "网络或服务器错误";
        }
        console.log(result)
        const userInfo = result.data.data;
        await uni.setStorage({
          key: "userInfo",
          data: userInfo,
        });
       
      } catch (e) {
        console.error("index", e);
        uni.showToast({
          title: `错误： ${e}`,
          icon: "error",
        });
      }
    })();
  },
  onShow(){
     uni.hideTabBar({
                animation: false
    })//掩饰官方的tabber
  },
  data() {
    return {
      // pattern:{
      //  buttonColor:"#ff6781"
      // },
      
      show: true,
      
      ///xgh重构
      tabActive:0
    };
  },
  methods: {
    // showDrawer() {
    //   this.$refs.showRight.open();
    // },
    // closeDrawer() {
    //   this.$refs.showRight.close();
    // }
    tabClickHandler(event){
      // console.log(event)
      let page = event.currentTarget.dataset.info 
      let url = `/pages/${page}/${page}`
      uni.switchTab({
	       url: url
      });
    }
  },
};
</script>

<style>
.container {
  padding: 10Upx 0;
  font-size: 14px;
  line-height: 24px;
}

.on-top {
  position: fixed;
  top: 0;
  width: 100%;
  z-index: 10;
}
</style>
